<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=result-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/admin.css" media="all"/>
    <script src="/layui/layui.js" type="text/javascript"></script>
    <script>
        ctx = "${ctxPath!}";
    </script>    <!-- jqgrid-->
    <link href="${ctxPath!}/css/bootstrap.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath!}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxPath!}/jqgrid/jqgrid.css" rel="stylesheet">
    <style>
        .ui-jqgrid-btable tbody tr td{
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
<div class="content-search">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal"  onclick="return add();">添加结果</a>
            </div>
        </form>
    </blockquote>
</div>
<!-- 内容主体区域 -->
<div style="padding: 2px;">
    <div class="jqGrid_wrapper">
        <table id="table"></table>
        <div id="pager" ></div>
    </div>
</div>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js?v=2.2.4"></script>
<script src="${ctxPath!}/jquery/jquery.form.js?v=3.50.0"></script>
<script src="${ctxPath!}/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/frozen.js?v=1.0.1"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script>

    layui.use('form', function(){
    });

    var colNames = ["ID","结果名称", "操作1","操作2"];
    var colModel = [{
        name : "id",
        index : "id",
        width : 50,
        hidden: true,
        align : "left"
    },{
        name : "name",
        index : "name",
        editable : false,
        align : "center"
    },{
        name : "action",
        index : "action",
        title:false,
        editable:true,
        align : "center",
        formatter : function(cellvalue, options, rowdata){
            var html = '<button type="button" class="layui-btn btn-edit" style="background-color: #607d8b" data-id="'+rowdata.id+'"  ><i class="layui-icon">&#xe642;</i>编辑结果</button>';
            return html;
        }
    },{
        name : "action",
        index : "action",
        title:false,
        editable:true,
        align : "center",
        formatter : function(cellvalue, options, rowdata){
            var html = '<button type="button" class="layui-btn btn-del" style="background-color: #9E9E9E;" data-id="'+rowdata.id+'"  ><i class="layui-icon">&#xe640;</i>删除结果</button>';
            return html;
        }
    }];
    var myJqGrid = null;
    $(document).ready(function () {
        myJqGrid = new MyJqGrid({
            jqGrid_id: 'table',
            data: "${ctxPath!}/console/result/list.json",
            isSubGrid: false,
            autowidth: true,
            shrinkToFit: true,
            autoScroll: true,
            colNames: colNames,
            colModel: colModel
        })
    });

    function add() {
        layer.open({
            title: '添加结果',
            type: 2,
            area: ['500px', '450px'],
            content: '${ctxPath!}/console/result/edit'
        });
        return false;
    }

    $(function(){

        $(document).on("click", ".btn-edit", function (e) {
            layer.open({
                title: '编辑结果',
                type: 2,
                area: ['500px', '450px'],
                content: '${ctxPath!}/console/result/edit?id='+$(this).data("id")
            });
        });

        $(document).on("click", ".btn-del", function (e) {
            var id = $(this).data("id");
            layer.confirm('确定删除该结果吗？', {
                icon: 3,
                btn: ['确定','取消'] //按钮
            }, function(){ //确定
                var params = {"id":id};
                console.log(id);
                $.post("${ctxPath!}/console/result/delete", params, function(data){
                    if(data.status == 200){
                        layer.alert(data.msg, {
                            icon: 1,
                            skin: 'layer-ext-moon'
                        },function () {
                            search();
                            layer.closeAll();
                        });
                    }else{
                        layer.alert(data.msg, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        });
                    }
                });
            }, function(){ //取消
            });
        });
    });

</script>
</body>
</html>